package com.hmall.mapper;

import com.hmall.model.MallOrder;
import com.hmall.model.MallOrderItem;
import com.hmall.model.MallPrice;
import com.hmall.util.MyMapper;
import com.hmall.vo.MallOrderItemManageVo;
import com.hmall.vo.OrderItemVo;
import com.hmall.vo.OrderSelectItemVo;
import com.hmall.vo.SpecialNameAndWeightVo;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Repository
public interface MallOrderItemMapper extends MyMapper<MallOrderItem> {
    List<MallOrderItem> getByOrderNoUserId(@Param("orderNo") Long orderNo, @Param("userId") Integer userId);

    List<MallOrderItemManageVo> selectByOrderNo(Long order_no);

    List<MallOrderItem> getByOrderNo(@Param("orderNo") Long orderNo);

    Integer deleteByOrderNo(@Param("orderNo") Long orderNo);

    Integer selectOrderId(@Param("id") Integer id);

    Integer updateOrderItem(@Param("id") Integer id, @Param("current_unit_price") BigDecimal current_unit_price, @Param("quantity") Integer quantity, @Param("total_price") BigDecimal total_price);
//批量添加产品明细
    int batchInsert(@Param("orderNo") Long orderNo, @Param("userId") Integer userId, @Param("itemList") List<OrderSelectItemVo> itemList);
//添加产品明细
    int insertQuk(@Param("orderNo") Long orderNo, @Param("userId") Integer userId, @Param("productId") Integer productId,
                  @Param("producName") String producName, @Param("productMainImage") String productMainImage,
                  @Param("productPrice") Double productPrice, @Param("weight") Integer weight,
                  @Param("productTotalPrice") Double productTotalPrice, @Param("grade") String grade,
                  @Param("commentCheck") Integer commentCheck,
                  @Param("productModel") String productModel
    );

    //找出产品明细表里的具体某个用户的所有的产品id
    List<Integer> findProductListByUser(@Param("userId") Integer userId);


    //根据用户id查询出未评价的订单
    List<MallOrderItem> findOrderItemByUser(@Param("userId") Integer userId, @Param("unComment") int unComment, @Param("pageStart") int pageStart, @Param("pageSize") int pageSize);

    //计算上述的总数
    int findProductListByUserCount(@Param("userId") Integer userId, @Param("unComment") int unComment);

    //列出所有相同的订单的销量
    List<Map<String, Object>> listGroupByProductId(@Param("successOrderList") List<BigInteger> successOrderList);

    //根据订单的id查询出productId
    int findProductIdByOrderItemId(@Param("orderItemId") Integer orderItemId);

    //组合查询 根据订单编号查询订单明细
    List<MallOrderItem> findOrderItemByOrderList(@Param("successOrderId") List<BigInteger> successOrderId);

    //组合查询 根据订单编号查询订单明细的数目
    int findOrderItemCountByOrderList(@Param("successOrderId") List<BigInteger> successOrderId,
                                      @Param("unComment") int unComment);

    void deleteByUserId(@Param("userId") Integer userId);

    List<OrderItemVo> findOrderItemByOrder(@Param("orderNumber") BigInteger orderNumber);

    Date selectUpdateTime(@Param("orderItemId") Integer orderItemId);

    int selectProductByOrderItem(@Param("orderItemId") Integer orderItemId);

    //批量查询
    List<MallOrderItem> selectByOrderNoList(@Param("orderNoList") List<BigInteger> orderNoList);

    void updateCommentCheck(@Param("commentId") Integer commentId);

    List<MallOrderItem> selectOrderItemByOrderNo(@Param("orderNo") Long orderNo);

    int selectCommentCheck(@Param("orderNo") Long a);

    List<MallOrderItem> selectByOrderNoListWithLong(@Param("orderNoList") List<Long> orderNoList);

    List<MallOrderItem> selectAllByOrderNo(@Param("orderNo") Long orderNo);

    MallOrderItem selectByOrderItemId(@Param("orderItemId") int orderItemId);

    void updateResidualQuantity(@Param("orderItemId") Integer orderItemId, @Param("weight") BigDecimal weight);

    Integer selectIsCommentByOrderNo(Long orderNo);

    Integer selectByProductIdAndGradeAndOrderNo(@Param("orderNo") Long orderNo, @Param("productId") Integer productId, @Param("grade") String grade);

    void updatePriceAndTwoQuantity(@Param("itemId") Integer itemId, @Param("unitPrice") BigDecimal unitPrice, @Param("price") BigDecimal orderItemPrice, @Param("quantity") BigDecimal orderItemQuantity);

    MallOrderItem selectByOrderNoAndGradeAndProductId(@Param("orderNo") Long orderNo, @Param("grade") String grade, @Param("productId") Integer productId);


    void updateBySubOrderDetial(@Param("itemId") Integer itemId, @Param("quantity") BigDecimal quantity, @Param("residualQuantity") BigDecimal residualQuantity,
                                @Param("totalPrice") BigDecimal totalPrice, @Param("unitPrice") BigDecimal unitPrice);

    List<MallPrice> selectByCountWithLimit(@Param("userId") Integer userId, @Param("start") Integer start, @Param("end") Integer end);

    Integer selectCountByUserId(@Param("userId") Integer userId);

    /**
     * 根据订单得到交易的总额
     * @param mallOrderList 订单
     * @return BigDecimal
     */
    BigDecimal selectTotalPriceByOrder(@Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * 根据订单得到交易的总重量
     * @param mallOrderList 订单
     * @return BigDecimal
     */
    BigDecimal selectTotalWeightByOrder(@Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * 根据订单和产品类型得到产品数目
     * @param type
     * @param mallOrderList
     * @return
     */
    BigDecimal selectCountByTypeAndOrderList(@Param("type") String type, @Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * 根据订单和排除的产品类型得到其他类型
     * @param mallOrderList
     * @return
     */
    BigDecimal selectOtherCountByTypeAndOrderList(@Param("mallOrderList") List<MallOrder> mallOrderList);

    /**
     * 根据订单编号得到总成交重量
     * @param orderNoList
     * @return
     */
    BigDecimal selectTotalWeightByOrderNoList(@Param("orderNoList") List<Long> orderNoList);

    BigDecimal selectTotalPriceByOrderNoList(@Param("orderNoList") List<Long> orderNoList);

    /**
     * 分组查询名称和订单
     * @param mallOrderList
     * @return
     */
    List<SpecialNameAndWeightVo> selectSpecialWeightByOrderList(@Param("mallOrderList") List<MallOrder> mallOrderList, @Param("type") String productType);

    /**
     * 根据产品名称和重量分组得到列表
     * @param orderList
     * @return
     */
    List<SpecialNameAndWeightVo> selectProductNameAndWeight(@Param("orderList") List<MallOrder> orderList);

    void deleteByOrderItemId(@Param("orderItemId") Integer id);

    void updateQuantity(@Param("orderNo") Long orderNo, @Param("number") BigDecimal bigDecimal);

    void updateTotalPrice(@Param("orderNo") Long orderNo, @Param("number") BigDecimal bigDecimal);
}